#pragma once

#include "noncopyable.h"
#include "Socket.h"
#include "Channel.h"

class EventLoop;
class InetAddress;

class Acceptor : noncopyable
{
public:
  using NewConnectionCallback = std::function<void(int sockfd, const InetAddress&)>;
  Acceptor(EventLoop *loop, const InetAddress &listenAddr, bool reusePort);
  ~Acceptor();
  void setNewConnectionCallback(const NewConnectionCallback &cb) { m_newConnectionCallback = std::move(cb); }
  bool listening() const { return m_listening; }
  void listen();
private:
  void handleRead();
private:
  EventLoop *m_loop; // baseLoop
  Socket m_acceptSocket;
  Channel m_acceptChannel;
  NewConnectionCallback m_newConnectionCallback;
  bool m_listening;    
};